-- Rogue Rage
-- Darren Grey - http://gruesomegames.com
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--

-- This file loads the game module, and loads data
local KeyBind = require "engine.KeyBind"


-- REMEMBER TO COMMENT OUT!!!
--[[KeyBind:defineAction{
   default = { "uni:h" },
   type = "HEAL",
   group = "actions",
   name = "Heal Potion",
}--]]
KeyBind:defineAction{
   default = { "uni: " },
   type = "PAUSE",
   group = "actions",
   name = "Pause",
}

-- Stone style ui (simple, stone and metal also options)
local UIBase = require "engine.ui.Base"
UIBase.ui = "simple"

local size = 18
UIBase.font = core.display.newFont("/data/font/DroidSans.ttf", size)
UIBase.font_bold = core.display.newFont("/data/font/DroidSans.ttf", size)
UIBase.font_mono = core.display.newFont("/data/font/DroidSansMono.ttf", size)
UIBase.font_bold:setStyle("bold")
UIBase.font_h = UIBase.font:lineSkip()
UIBase.font_bold_h = UIBase.font_bold:lineSkip()
UIBase.font_mono_w = UIBase.font_mono:size(" ")
UIBase.font_mono_h = UIBase.font_mono:lineSkip()+2

-- For smooth movement
local Map = require "engine.Map"
Map.smooth_scroll = 3

local DamageType = require "engine.DamageType"
local ActorInventory = require "engine.interface.ActorInventory"
local ActorStats = require "engine.interface.ActorStats"
local ActorResource = require "engine.interface.ActorResource"
-- local ActorTalents = require "engine.interface.ActorTalents"
local ActorAI = require "engine.interface.ActorAI"
local ActorLevel = require "engine.interface.ActorLevel"
-- local ActorTemporaryEffects = require "engine.interface.ActorTemporaryEffects"
local Birther = require "engine.Birther"


-- Useful keybinds
KeyBind:load("move,hotkeys,inventory,actions,interface,debug")

-- Damage types
DamageType:loadDefinition("/data/damage_types.lua")

-- Talents
-- ActorTalents:loadDefinition("/data/talents.lua")

-- Timed Effects
-- ActorTemporaryEffects:loadDefinition("/data/timed_effects.lua")


-- Actor resources

-- Actor stats
--[[ActorStats:defineStat("Power",	"pow", 10, 1, 100, "..")
ActorStats:defineStat("Aim",	"aim", 10, 1, 100, "..")
ActorStats:defineStat("Dodge",	"dod", 10, 1, 100, "..")
ActorStats:defineStat("Armour",	"arm", 10, 1, 100, "..")
ActorStats:defineStat("Speed",	"spd", 10, 1, 100, "..")--]]

-- Equipment
ActorInventory:defineInventory("WEAPON", "Weapon", true, "Hit 'em with it!")

-- Actor AIs
ActorAI:loadDefinition("/engine/ai/")

-- Birther descriptor
Birther:loadDefinition("/data/birth/descriptors.lua")

-- Enable hex mode
--core.fov.set_algorithm("hex")

-- Wall-sliding
config.settings.player_slide = true

-- Switch to realtime, with 10 ticks per second
--core.game.setRealtime(10)

-- Makes ASCII on ASCII work somehow.  Just doing what DarkGod told me to do....
local Map = require "engine.Map"
Map.updateMapDisplay = function (self, x, y, mos)
   local g = self(x, y, self.TERRAIN)
   local gb = nil
   --local o = self(x, y, self.OBJECT)
   local a = self(x, y, self.ACTOR)
   --local t = self(x, y, self.TRAP)
   local p = self(x, y, self.PROJECTILE)
   if g then
      -- Update path caches from path strings
      for i = 1, #self.path_strings do
         local ps = self.path_strings[i]
         self._fovcache.path_caches[ps]:set(x, y, g:check("block_move", x, y, ps, false, true))
      end

      g:getMapObjects(self.tiles, mos, 1)
      g:setupMinimapInfo(g._mo, self)
      if g.default_tile then gb = g.default_tile end
   end
   --[[if t then
      -- Handles trap being known
      if not self.actor_player or t:knownBy(self.actor_player) then
         t:getMapObjects(self.tiles, mos, 3)
         t:setupMinimapInfo(t._mo, self)
      else
         t = nil
      end
   end
   if o then
      o:getMapObjects(self.tiles, mos, 3)
      o:setupMinimapInfo(o._mo, self)
      if self.object_stack_count then
         local mo = o:getMapStackMO(self, x, y)
         if mo then mos[5] = mo end
      end
   end--]]
   if a then
      -- Handles invisibility and telepathy and other such things
      if not self.actor_player or self.actor_player:canSee(a) then
         a:getMapObjects(self.tiles, mos, 3)
         a:setupMinimapInfo(a._mo, self)
      end
   end
   if p then
      p:getMapObjects(self.tiles, mos, 3)
      p:setupMinimapInfo(p._mo, self)
   end

   --if gb and not p and (not a or (self.actor_player and not self.actor_player.fov.actors[a])) then
   --if gb and not p and (not a or not self.actor_player:hasLOS(a.x, a.y) or not self.actor_player:canSee(a)) then
   if gb and not p and (not a or not self.actor_player:canSee(a)) then
      gb:getMapObjects(self.tiles, mos, 3)
   end
end

return {require "mod.class.Game", require "mod.class.World"}
